﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OnTheWay.Command;

namespace PcBackgroundMgr.Controls
{
    public class EditableCtrl : ContentControl
    {
        public EditableCtrl()
        {
            //CommandDelete = new DelegateCommand(OnCommandDelete, OnCanCommandDelete, "", "删除");
            //CommandModify = new DelegateCommand(OnCommandModify, OnCanCommandModify, "", "编辑");
        }

        public bool IsReadOnly
        {
            get { return (bool)GetValue(IsReadOnlyProperty); }
            set { SetValue(IsReadOnlyProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsReadOnly.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsReadOnlyProperty =
            DependencyProperty.Register("IsReadOnly", typeof(bool),
            typeof(EditableCtrl), new UIPropertyMetadata(false));


        public bool CanModify
        {
            get { return (bool)GetValue(CanModifyProperty); }
            set { SetValue(CanModifyProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CanModify.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CanModifyProperty =
            DependencyProperty.Register("CanModify", typeof(bool),
            typeof(EditableCtrl), new UIPropertyMetadata(true));


        public bool CanDelete
        {
            get { return (bool)GetValue(CanDeleteProperty); }
            set { SetValue(CanDeleteProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CanDelete.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CanDeleteProperty =
            DependencyProperty.Register("CanDelete", typeof(bool),
            typeof(EditableCtrl), new UIPropertyMetadata(true));

        

        public string DeleteText
        {
            get { return (string)GetValue(DeleteTextProperty); }
            set { SetValue(DeleteTextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DeleteText.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DeleteTextProperty =
            DependencyProperty.Register("DeleteText", typeof(string),
            typeof(EditableCtrl), new UIPropertyMetadata("删除"));

        /// <summary>
        /// 删除命令
        /// </summary>
        public DelegateCommand CommandDelete
        {
            get { return (DelegateCommand)GetValue(CommandDeleteProperty); }
            set { SetValue(CommandDeleteProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CommandDelete.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandDeleteProperty =
            DependencyProperty.Register("CommandDelete", typeof(DelegateCommand),
            typeof(EditableCtrl), new UIPropertyMetadata(null));

        public object CommandDeleteParameter
        {
            get { return (object)GetValue(CommandDeleteParameterProperty); }
            set { SetValue(CommandDeleteParameterProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CommandDeleteParameter.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandDeleteParameterProperty =
            DependencyProperty.Register("CommandDeleteParameter", typeof(object),
            typeof(EditableCtrl), new UIPropertyMetadata(null));

        //protected virtual bool OnCanCommandDelete(object param)
        //{
        //    return IsReadOnly == false;
        //}


        //protected virtual void OnCommandDelete(object param)
        //{
        //    base.RaiseEvent(new RoutedEventArgs(OnDeleteEvent, base.DataContext));
        //}

        //public static readonly RoutedEvent OnDeleteEvent = EventManager.RegisterRoutedEvent("OnDeleteEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ExhibitItemCtrl));

        //public event RoutedEventHandler OnDelete
        //{
        //    add { base.AddHandler(OnDeleteEvent, value); }
        //    remove { base.RemoveHandler(OnDeleteEvent, value); }
        //}


        public string ModifyText
        {
            get { return (string)GetValue(ModifyTextProperty); }
            set { SetValue(ModifyTextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ModifyText.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ModifyTextProperty =
            DependencyProperty.Register("ModifyText", typeof(string),
            typeof(EditableCtrl), new UIPropertyMetadata("编辑"));

        /// <summary>
        /// 编辑命令
        /// </summary>
        public DelegateCommand CommandModify
        {
            get { return (DelegateCommand)GetValue(CommandModifyProperty); }
            set { SetValue(CommandModifyProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CommandModify.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandModifyProperty =
            DependencyProperty.Register("CommandModify", typeof(DelegateCommand),
            typeof(EditableCtrl), new UIPropertyMetadata(null));

        public object CommandModifyParameter
        {
            get { return (object)GetValue(CommandModifyParameterProperty); }
            set { SetValue(CommandModifyParameterProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CommandModifyParameter.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandModifyParameterProperty =
            DependencyProperty.Register("CommandModifyParameter", typeof(object),
            typeof(EditableCtrl), new UIPropertyMetadata(null));

        //protected virtual bool OnCanCommandModify(object param)
        //{
        //    return IsReadOnly == false;
        //}

        //protected virtual void OnCommandModify(object param)
        //{
        //    base.RaiseEvent(new RoutedEventArgs(OnModifyEvent, base.DataContext));
        //}

        //public static readonly RoutedEvent OnModifyEvent = EventManager.RegisterRoutedEvent("OnModifyEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ExhibitItemCtrl));

        //public event RoutedEventHandler OnModify
        //{
        //    add { base.AddHandler(OnModifyEvent, value); }
        //    remove { base.RemoveHandler(OnModifyEvent, value); }
        //}
    }
}
